﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Security.Cryptography;

namespace XYTXL.Web.View
{


    public partial class CWPacQuerry : System.Web.UI.Page
    {

        public string sign;
        public string sysid;
        //string data;
        public string data;
        public string subsysid;
        string cert = "601CCD54D7EEF7A3E050230A0164565F601CCD54D7EFF7A3E050230A0164565F601CCD54D7F0F7A3E050230A0164565F601CCD54D7F1F7A3E050230A0164565F601CCD54D7F2F7A3E050230A0164565F601CCD54D7F3F7A3E050230A0164565F601CCD54D7F4F7A3E050230A0164565F601CCD54D7F5F7A3E050230A0164565F601CCD54D7F6F7A3E050230A0164565F601CCD54D7F7F7A3E050230A0164565F601CCD54D7F8F7A3E050230A0164565F601CCD54D7F9F7A3E050230A0164565F601CCD54D7FAF7A3E050230A0164565F601CCD54D7FBF7A3E050230A0164565F601CCD54D7FCF7A3E050230A0164565F601CCD54D7FDF7A3E050230A0164565F601CCD54D7FEF7A3E050230A0164565F601CCD54D7FFF7A3E050230A0164565F601CCD54D800F7A3E050230A0164565F601CCD54D801F7A3E050230A0164565F601CCD54D802F7A3E050230A0164565F601CCD54D803F7A3E050230A0164565F601CCD54D804F7A3E050230A0164565F601CCD54D805F7A3E050230A0164565F601CCD54D806F7A3E050230A0164565F601CCD54D807F7A3E050230A0164565F601CCD54D808F7A3E050230A0164565F601CCD54D809F7A3E050230A0164565F601CCD54D80AF7A3E050230A0164565F601CCD54D80BF7A3E050230A0164565F601CCD54D80CF7A3E050230A0164565F601CCD54D80DF7A3E050230A0164565F";
        public string billno;
            //= "<?xml version=\"1.0\" encoding=\"GBK\"?><billinfo><version>1.0.0.2</version><billno>201712262105</billno><orderinfono>0130209098</orderinfono><orderinfoname>吕凤强</orderinfoname><returnURL>http://www.baidu.com</returnURL><billdtl><feeitemid>001-01</feeitemid><feeord>1</feeord><amt>0.1</amt></billdtl></billinfo>";


        protected void Page_Load(object sender, EventArgs e)
        {
            //xml = Request["data"];
            billno = "xy2017121401";
            sysid = "08";
            subsysid = "201703";
            //data=Encoding.UTF8.GetBytes(xml);
            string st = sysid + subsysid + cert + billno;
            sign = GetMd5Hash(LanChange(st));
            // sign =


        }

        public static string GetMd5Hash(string input)
        {
            //MD5 md5Hash = new MD5();
            MD5 md5Hash = MD5.Create();
            // Convert the input string to a byte array and compute the hash.
            byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));

            // Create a new Stringbuilder to collect the bytes
            // and create a string.
            StringBuilder sBuilder = new StringBuilder();

            // Loop through each byte of the hashed data 
            // and format each one as a hexadecimal string.
            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }

            // Return the hexadecimal string.
            return sBuilder.ToString();
        }

        string LanChange(string str)
        {
            System.Text.Encoding utf8, gbk;
            utf8 = System.Text.Encoding.GetEncoding("UTF-8");
            gbk = System.Text.Encoding.GetEncoding("GBK");
            byte[] gb;
            gb = gbk.GetBytes(str);
            gb = System.Text.Encoding.Convert(gbk, utf8, gb);

            return utf8.GetString(gb);
        }
    }
}